﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace RPGProject.IOBuffers
{
    /// <summary>
    /// A class to hold and render character info as specified.
    /// </summary>
    class CharInfo
    {
        /// <summary>
        /// The character to be rendered/
        /// </summary>
        public char c;
        /// <summary>
        /// Foreground color.
        /// </summary>
        public ConsoleColor foreground;
        /// <summary>
        /// Background color.
        /// </summary>
        public ConsoleColor background;
        private bool rendered;
        public override bool Equals(object obj)
        {
            if (obj.GetType() == this.GetType())
            {
                return this.Equals((CharInfo)obj);
            }
            else
            {
                return false;
            }
        }
        public override int GetHashCode()
        {
            return base.GetHashCode() + this.c.GetHashCode() + this.foreground.GetHashCode() + this.background.GetHashCode();
        }
        public bool Equals(CharInfo c1)
        {
            return c1.c == this.c && c1.foreground == this.foreground && c1.background == this.background;
        }

        public static bool operator ==(CharInfo c1, CharInfo c2)
        {
            return c1.Equals(c2);
        }
        public static bool operator !=(CharInfo c1, CharInfo c2)
        {
            return !c1.Equals(c2);
        }

        /// <summary>
        /// Returns whather the character has been rendered.
        /// </summary>
        /// <returns>Render Status</returns>
        public bool IsRendered()
        {
            return rendered;
        }

        /// <summary>
        /// Renders the character to the current character position.
        /// </summary>
        public void Render()
        {
            Console.ForegroundColor = this.foreground;
            Console.BackgroundColor = this.background;
            Console.Write(this.c);
            this.rendered = true;
        }

        /// <summary>
        /// Creates a CharInfo with default coloring of the specified character.
        /// </summary>
        /// <param name="c">Character to be rendered.</param>
        public CharInfo(char c)
            : this(c, ConsoleColor.White, ConsoleColor.Black)
        {
        }

        /// <summary>
        /// Creates a space CharInfo with foreground and background as specified.
        /// </summary>
        /// <param name="fore">Text color to be rendered.</param>
        /// <param name="back">Background color to be rendered.</param>
        public CharInfo(ConsoleColor fore, ConsoleColor back)
            : this(' ', fore, back)
        {
        }

        /// <summary>
        /// Creates a space CharInfo with white text and background as specified.
        /// </summary>
        /// <param name="back">Background color to be rendered.</param>
        public CharInfo(ConsoleColor back)
            : this(ConsoleColor.White, back)
        {
        }

        /// <summary>
        /// Creates a CharInfo as specified.
        /// </summary>
        /// <param name="c">Character to be rendered.</param>
        /// <param name="fore">Text color to be rendered.</param>
        /// <param name="back">Background color to be rendered.</param>
        public CharInfo(char c, ConsoleColor fore, ConsoleColor back)
        {
            this.c = c;
            this.foreground = fore;
            this.background = back;
            this.rendered = false;
        }

        /// <summary>
        /// Copy constructer.  Does not retain updatedness.
        /// </summary>
        /// <param name="info"></param>
        public CharInfo(CharInfo info) : this(info.c, info.foreground, info.background)
        {
        }
    }
}
